<!--
 * @Author: your name
 * @Date: 2021-11-09 20:51:22
 * @LastEditTime: 2021-11-19 08:35:57
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AEl
 * @FilePath: \li-yuwei\admin\src\views\login\index.vue
-->
<template>
  <div class="login">
    <div class="login-box">
      <div class="left-login-box">
        <img :src="loginImg" alt="" />
      </div>
      <div class="right-login-box">
        <div class="login-main">
          <div class="login-title">系统登录</div>
          <el-form
            :model="ruleForm"
            :rules="rules"
            ref="ruleForm"
            label-width="100px"
            class="demo-ruleForm"
          >
            <el-form-item label="账户" prop="username">
              <el-input
                v-model="ruleForm.username"
                placeholder="请输入用户名"
              ></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="password">
              <el-input
                v-model="ruleForm.password"
                type="password"
                placeholder="请输入密码"
              ></el-input>
            </el-form-item>
          </el-form>
          <div class="login-btn-box">
            <el-button type="primary" @click="submitForm()">登录</el-button>
          </div>
          <div class="or-box" @click="goRegister()">Or 注册用户</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import loginImg from "../../assets/登录.webp";
import { mapMutations, mapState, mapActions } from "vuex";
export default {
  computed: {
    ...mapState(["a"]),
  },
  data() {
    return {
      loginImg,
      ruleForm: {
        username: "",
        password: "",
      },
      rules: {
        username: [{ required: true, message: "请输入用户名!" }],
        password: [{ required: true, message: "请输入密码!" }],
      },
    };
  },
  methods: {
    ...mapMutations(["set_routes", "resetRefreshNum"]),
    ...mapActions(["Login"]),
    submitForm() {
      //调用登录接口
      if (this.ruleForm.username && this.ruleForm.password) {
        this.Login(this.ruleForm);
      } else {
        this.$message({
          message: "请正确输入内容",
          type: "warning",
        });
      }
    },
    goRegister() {
      this.$router.push("/register");
    },
  },
  created() {
    this.resetRefreshNum();
  },
};
</script>

<style lang="scss" scoped>
.login {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #e7eaee;
}
.login-box {
  width: 85%;
  height: 85%;
  background-color: #fff;
  display: flex;
}
.left-login-box {
  height: 100%;
  img {
    height: 100%;
  }
}
.right-login-box {
  flex: 1;
  background-color: #f7fafb;
  display: flex;
  align-items: center;
  .login-main {
    width: 100%;
    padding: 0 20px;
  }
}
.login-title {
  margin-left: 50px;
  margin-bottom: 20px;
  font-size: 20px;
}
.login-btn-box {
  width: 100%;
  display: flex;
  justify-content: center;
  button {
    width: 94%;
    margin-left: 48px;
  }
}
.or-box {
  font-size: 12px;
  font-weight: normal;
  margin-left: 48px;
  margin-top: 10px;
  cursor: pointer;
}
</style>
